package com.winderinfo.yikaotianxia.ui.xiangqin;

import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.base.BaseFragment;
import com.winderinfo.yikaotianxia.core.utils.AutofitHeightViewPager;
import com.winderinfo.yikaotianxia.core.utils.ToastUtil;
import com.winderinfo.yikaotianxia.ui.zixun.InformationxqBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class CourseDetailsFragment extends BaseFragment {
    @BindView(R.id.cdf_view)
    WebView cdfView;
    Unbinder unbinder;

    //发现部分图片 的html 标签 没有定义 width 和hight 属性，默认的还是图像大小，造成了还是图片没有适应屏幕。
    //解决思路：找到所有的img 标签把它的宽高属性全部重置定死。
    //添加了一句js 代码。
    String varjs = "<script type='text/javascript'> \nwindow.onload = function()\n{var $img = document.getElementsByTagName('img');for(var p in  $img){$img[p].style.width = '100%'; $img[p].style.height ='auto'}}</script>";

    @Override
    protected int initLayoutId() {
        return R.layout.fragment_cdf;
    }

    @Override
    protected void initView(View view) {
    }

    @Override
    protected void initData() {
        //H5
        String details = getArguments().getString("details");
        //解析H5
        cdfView.getSettings().setJavaScriptEnabled(true);
        cdfView.loadDataWithBaseURL("", varjs + details, "text/html", "UTF-8", null);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
